//
//  SettingViewController.m
//  LightMeter
//
//  Created by alex tao on 5/23/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "SettingViewController.h"

@interface SettingViewController ()

@end

@implementation SettingViewController
@synthesize toolBar;
@synthesize segmentCtrl;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    NSString * curUnit = [[NSUserDefaults standardUserDefaults] objectForKey:@"keyUnit"];
    if (curUnit) {
        if ([curUnit isEqualToString:@"lux"]) {
            self.segmentCtrl.selectedSegmentIndex = 0;
        } else {
            self.segmentCtrl.selectedSegmentIndex = 1;
        }
    }
}

- (void)viewDidUnload
{
    [self setToolBar:nil];
    [self setSegmentCtrl:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)okClicked:(id)sender {
    [self dismissModalViewControllerAnimated:YES];
}

- (IBAction)segmentChange:(id)sender {
    switch([sender selectedSegmentIndex]){
        case 0:
            [[NSUserDefaults standardUserDefaults] setObject:@"lux" forKey:@"keyUnit"];
            break;
        case 1:
            [[NSUserDefaults standardUserDefaults] setObject:@"fc" forKey:@"keyUnit"];
            break;
        default:
            break;
    }
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (void)dealloc {
    [toolBar release];
    [segmentCtrl release];
    [super dealloc];
}

@end
